<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="搬砖 嵌入式">
<meta property="og:type" content="website">
<meta property="og:title" content="学无止境">
<meta property="og:url" content="http://example.com/page/18/index.html">
<meta property="og:site_name" content="学无止境">
<meta property="og:description" content="搬砖 嵌入式">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="xudonglei">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/page/18/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>学无止境</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">学无止境</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Do not bb, show me the example</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/03/09/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%BA%8C(%E4%B8%8A%E4%BB%A3%E7%A0%81)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/03/09/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%BA%8C(%E4%B8%8A%E4%BB%A3%E7%A0%81)/" class="post-title-link" itemprop="url">FIR滤波器简介二(上代码)</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-03-09 22:52:42" itemprop="dateCreated datePublished" datetime="2022-03-09T22:52:42+08:00">2022-03-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          
            <span id="/2022/03/09/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%BA%8C(%E4%B8%8A%E4%BB%A3%E7%A0%81)/" class="post-meta-item leancloud_visitors" data-flag-title="FIR滤波器简介二(上代码)" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/03/09/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%BA%8C(%E4%B8%8A%E4%BB%A3%E7%A0%81)/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/03/09/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%BA%8C(%E4%B8%8A%E4%BB%A3%E7%A0%81)/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        直接形式FIR滤波器图解如下：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203092259649.webp"></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203092301208.png" style="zoom:80%;">

<p>代码里如果使用linear buffering这样的数组，理解上会简单，但是效率会低。具体可以参考网上一篇好文：<a target="_blank" rel="noopener" href="https://www.allaboutcircuits.com/technical-articles/circular-buffer-a-critical-element-of-digital-signal-processors/">https://www.allaboutcircuits.com/technical-articles/circular-buffer-a-critical-element-of-digital-signal-processors/</a></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203092304775.png" style="zoom:60%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203092305251.png" style="zoom:80%;">

<p>​        <strong>提高效率的一个办法就是使用循环缓冲区。</strong></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203092308196.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203092309754.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203092310296.png" style="zoom:67%;">

<p>哈哈，这边就不写文字了，文字反而啰嗦，直接上那个博文里面的图片，言简意赅。</p>
<p>下面直接贴代码，代码来源于：<a target="_blank" rel="noopener" href="https://github.com/pms67/LittleBrain-STM32F4-Sensorboard">https://github.com/pms67/LittleBrain-STM32F4-Sensorboard</a></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">ifndef</span> FIR_FILTER_H</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> FIR_FILTER_H</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stdint.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> FIR_FILTER_LENGTH 10</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> </span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">	<span class="keyword">float</span> 	buf[FIR_FILTER_LENGTH];</span><br><span class="line">	<span class="keyword">uint8_t</span> bufIndex;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">float</span> out;</span><br><span class="line">&#125; FIRFilter;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">FIRFilter_Init</span><span class="params">(FIRFilter *fir)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">float</span> <span class="title">FIRFilter_Update</span><span class="params">(FIRFilter *fir, <span class="keyword">float</span> inp)</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&quot;FIRFilter.h&quot;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">float</span> FIR_IMPULSE_RESPONSE[FIR_FILTER_LENGTH] = &#123;<span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>, <span class="number">0.1f</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">FIRFilter_Init</span><span class="params">(FIRFilter *fir)</span> </span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="comment">/* Clear filter buffer */</span></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">uint8_t</span> n = <span class="number">0</span>; n &lt; FIR_FILTER_LENGTH; n++) </span><br><span class="line">	&#123;</span><br><span class="line">		fir-&gt;buf[n] = <span class="number">0.0f</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">/* Reset buffer index */</span></span><br><span class="line">	fir-&gt;bufIndex = <span class="number">0</span>;</span><br><span class="line">	<span class="comment">/* Clear filter output */</span></span><br><span class="line">	fir-&gt;out = <span class="number">0.0f</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">接收最新的输入样本，并且返回最新的过滤输出。</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">float</span> <span class="title">FIRFilter_Update</span><span class="params">(FIRFilter *fir, <span class="keyword">float</span> inp)</span> </span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">	<span class="comment">/* 将最新的输入样本存到循环缓冲区中，</span></span><br><span class="line"><span class="comment">	   循环缓冲区索引指向循环缓冲区中的最新输入样本</span></span><br><span class="line"><span class="comment">	*/</span></span><br><span class="line">	fir-&gt;buf[fir-&gt;bufIndex] = inp;</span><br><span class="line"></span><br><span class="line">	<span class="comment">/* 增加缓冲区索引 and wrap around if necessary */</span></span><br><span class="line">	fir-&gt;bufIndex++;</span><br><span class="line">	<span class="keyword">if</span> (fir-&gt;bufIndex == FIR_FILTER_LENGTH) </span><br><span class="line">	&#123;</span><br><span class="line">		fir-&gt;bufIndex = <span class="number">0</span>;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">/* Compute new output sample (via convolution) */</span></span><br><span class="line">	<span class="comment">/*将输出先设置为0，后面要用来存储最新的输出样本的*/</span></span><br><span class="line">	fir-&gt;out = <span class="number">0.0f</span>;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">uint8_t</span> sumIndex = fir-&gt;bufIndex;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> (<span class="keyword">uint8_t</span> n = <span class="number">0</span>; n &lt; FIR_FILTER_LENGTH; n++) </span><br><span class="line">	&#123;</span><br><span class="line">		<span class="comment">/* Decrement index and wrap if necessary */</span></span><br><span class="line">		<span class="keyword">if</span> (sumIndex &gt; <span class="number">0</span>) </span><br><span class="line">		&#123;</span><br><span class="line">			sumIndex--;</span><br><span class="line">		&#125; </span><br><span class="line">		<span class="keyword">else</span> </span><br><span class="line">		&#123;</span><br><span class="line">			sumIndex = FIR_FILTER_LENGTH - <span class="number">1</span>;</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		<span class="comment">/* Multiply impulse response with shifted input sample and add to output */</span></span><br><span class="line">		fir-&gt;out += FIR_IMPULSE_RESPONSE[n] * fir-&gt;buf[sumIndex];</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">/* Return filtered output */</span></span><br><span class="line">	<span class="keyword">return</span> fir-&gt;out;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/03/08/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%B8%80/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/03/08/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%B8%80/" class="post-title-link" itemprop="url">FIR滤波器简介一</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-03-08 20:58:33" itemprop="dateCreated datePublished" datetime="2022-03-08T20:58:33+08:00">2022-03-08</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          
            <span id="/2022/03/08/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%B8%80/" class="post-meta-item leancloud_visitors" data-flag-title="FIR滤波器简介一" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/03/08/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%B8%80/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/03/08/FIR%E6%BB%A4%E6%B3%A2%E5%99%A8%E7%AE%80%E4%BB%8B%E4%B8%80/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考的一些资料链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_39371411/article/details/115049185">https://blog.csdn.net/qq_39371411/article/details/115049185</a></p>
<h3 id="一-基本原理："><a href="#一-基本原理：" class="headerlink" title="一.基本原理："></a>一.基本原理：</h3><p>​        考虑该问题时应该由频域至时域考虑，首先频域上我们可以很直接的想到不同频率对应各自的功率值，这些功率值代表着信号的强度即信号的存在与否，我们进行滤波时就是要把所需频段的信号保留下来并且使其他频段的信号强度为0，当然这只是理想情况，那么反映到实际我们感受更直观的逻辑元器件即编程代码中我们多要做的是什么呢？<br>​        从数学角度来看，我们想把一个函数的某个部分保留下来，最直接的想法就是乘上一个函数（需要保留的频段输出值为1，不需要保留的频段值为0），那么反映到时域上应该如何表示呢？首先可以想到一定与离散时域到频域的转换（z变换）有关，在频域上用来与原信号相乘进而达到滤波目的的函数我们可以设它为H(z)，由于频域是由时域z变换而来。对于H(z)来说我们可以根据z变换公式看出它是由一系列参数h(n)以及相应的z^{-n}所决定的。在频域上乘z^{-n0}相当于在时域上卷积相当于延时n0。综合上述的一切，我们可以得出这样一个结论：要实现实际的滤波，我们需要完成一系列延时和累加工作。</p>
<h3 id="二、举个最简单例子"><a href="#二、举个最简单例子" class="headerlink" title="二、举个最简单例子"></a>二、举个最简单例子</h3><p>​        看一个最简单的FIR滤波(滑动平均)：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082112686.png" style="zoom:60%;">

<p>这个窗口会一直滑动，每滑动一下求出一个值。</p>
<p>​        换一个角度看上面这个问题，比如说有0~N这么多个样本点。</p>
<p>​        比如现在你说一个3阶的FIR，其实是在说什么事情呢？比如上面这个例子就是5阶的，那3阶FIR就是会取3个点。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082122935.png" style="zoom:50%;">

<p>所以<strong>FIR通用的实现是：把每一个样本点去乘以一个对应的系数，然后再求和</strong>。滑动平均正好是把这里的系数都取成了N分之一。<strong>另外把上面这两个图合起来看，其实就是一个卷积的过程</strong>。</p>
<h3 id="三、设计一个简单的滤波器"><a href="#三、设计一个简单的滤波器" class="headerlink" title="三、设计一个简单的滤波器"></a>三、设计一个简单的滤波器</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082154794.png" style="zoom:70%;">

<p>比如H(f)那个低通滤波器，经过IFFT得到时域的函数h(t)。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082157826.png" style="zoom:70%;">

<p>输入信号f(t)和h(t)做卷积就等于这个图片上面部分频域的乘积，最后频域上只剩下一条竖线。（就是下面这个正弦波）</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082200429.png" style="zoom:67%;">

<p>上面这些就是一个滤波过程，<strong>滤波过程实际它的本质就是一个卷积的过程</strong>。</p>
<h3 id="四、FIR那边的系数设计直观感受"><a href="#四、FIR那边的系数设计直观感受" class="headerlink" title="四、FIR那边的系数设计直观感受"></a>四、FIR那边的系数设计直观感受</h3><p>​    比如说现在要一个低通，还是用上面图中的H(f)作为例子。我们对他进行IFFT，得到h(t)，我们知道了它的时域表达是什么样子了。这个时域信号h(t)不就是这个系数组吗？我们从中取离散的一些点出来，如下图黄颜色部分。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082206643.png" style="zoom:67%;">

<p>实际应该不是这样设计的，这里这么说只是直观上方便理解。</p>
<p>​    这组系数实际上就是滤波器的冲击响应离散化后的结果，这个用matlab的那个滤波器设计工具就可以很明显的发现这个端倪。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082239240.png" style="zoom:80%;">

<p><strong>这个图中冲击响应的一个个点不就是我上面那个图中黄颜色的那一个个点嘛</strong>。</p>
<h3 id="补充"><a href="#补充" class="headerlink" title="补充"></a>补充</h3><p>​        平均其实也是一个低通，只是这个低通的效果比较差。比如下面这个系数是1/4，1/4，1/4，1/4的例子。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202203082220798.png" style="zoom:67%;">


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/03/06/%E5%8C%88%E7%89%99%E5%88%A9%E7%AE%97%E6%B3%95%E8%A7%A3%E5%86%B3%E6%8C%87%E6%B4%BE%E9%97%AE%E9%A2%98/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/03/06/%E5%8C%88%E7%89%99%E5%88%A9%E7%AE%97%E6%B3%95%E8%A7%A3%E5%86%B3%E6%8C%87%E6%B4%BE%E9%97%AE%E9%A2%98/" class="post-title-link" itemprop="url">匈牙利算法解决指派问题</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-03-06 18:28:28" itemprop="dateCreated datePublished" datetime="2022-03-06T18:28:28+08:00">2022-03-06</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">算法</span></a>
                </span>
            </span>

          
            <span id="/2022/03/06/%E5%8C%88%E7%89%99%E5%88%A9%E7%AE%97%E6%B3%95%E8%A7%A3%E5%86%B3%E6%8C%87%E6%B4%BE%E9%97%AE%E9%A2%98/" class="post-meta-item leancloud_visitors" data-flag-title="匈牙利算法解决指派问题" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/03/06/%E5%8C%88%E7%89%99%E5%88%A9%E7%AE%97%E6%B3%95%E8%A7%A3%E5%86%B3%E6%8C%87%E6%B4%BE%E9%97%AE%E9%A2%98/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/03/06/%E5%8C%88%E7%89%99%E5%88%A9%E7%AE%97%E6%B3%95%E8%A7%A3%E5%86%B3%E6%8C%87%E6%B4%BE%E9%97%AE%E9%A2%98/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考的原文链接为：<a target="_blank" rel="noopener" href="https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.optimize.linear_sum_assignment.html">https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.optimize.linear_sum_assignment.html</a></p>
<p>​        <a target="_blank" rel="noopener" href="https://www.jianshu.com/p/9be417cbfebb">https://www.jianshu.com/p/9be417cbfebb</a></p>
<p>​        <a target="_blank" rel="noopener" href="https://blog.csdn.net/your_answer/article/details/79160045">https://blog.csdn.net/your_answer/article/details/79160045</a></p>
<p>​        <a target="_blank" rel="noopener" href="https://www.cnblogs.com/youmuchen/p/14660444.html">https://www.cnblogs.com/youmuchen/p/14660444.html</a></p>
<h3 id="一、指派问题"><a href="#一、指派问题" class="headerlink" title="一、指派问题"></a>一、指派问题</h3><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220306183430.png" style="zoom:80%;">

<h3 id="二、python解决指派问题"><a href="#二、python解决指派问题" class="headerlink" title="二、python解决指派问题"></a>二、python解决指派问题</h3><p>​        可以使用scipy.optimize.linear_sum_assignment(cost_matrix)这个函数。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20220306184139.png"></p>
<p>直接看一个代码例子：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> scipy.optimize <span class="keyword">import</span> linear_sum_assignment</span><br><span class="line"> </span><br><span class="line">cost =np.array([[<span class="number">4</span>,<span class="number">1</span>,<span class="number">3</span>],[<span class="number">2</span>,<span class="number">0</span>,<span class="number">5</span>],[<span class="number">3</span>,<span class="number">2</span>,<span class="number">2</span>]])</span><br><span class="line">row_ind,col_ind=linear_sum_assignment(cost)</span><br><span class="line">print(row_ind)<span class="comment">#开销矩阵对应的行索引</span></span><br><span class="line">print(col_ind)<span class="comment">#对应行索引的最优指派的列索引</span></span><br><span class="line">print(cost[row_ind,col_ind])<span class="comment">#提取每个行索引的最优指派列索引所在的元素，形成数组</span></span><br><span class="line">print(cost[row_ind,col_ind].<span class="built_in">sum</span>())<span class="comment">#数组求和</span></span><br><span class="line"></span><br><span class="line">输出结果：</span><br><span class="line">[<span class="number">0</span> <span class="number">1</span> <span class="number">2</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">0</span> <span class="number">2</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">2</span>]</span><br><span class="line"><span class="number">5</span></span><br></pre></td></tr></table></figure>
<h3 id="三、匈牙利算法解决两个坐标列表匹配的问题"><a href="#三、匈牙利算法解决两个坐标列表匹配的问题" class="headerlink" title="三、匈牙利算法解决两个坐标列表匹配的问题"></a>三、匈牙利算法解决两个坐标列表匹配的问题</h3><p>​        有一个坐标列表A：[[10,20],[20,30],[42,41]]，和一个坐标列表B：[[14,24],[41,42],[20,31],[42,41]]，需要看这两个坐标列表之间谁与谁更加匹配。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> scipy.optimize <span class="keyword">import</span> linear_sum_assignment</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="comment"># 先前的坐标</span></span><br><span class="line">position_a = [[<span class="number">10</span>,<span class="number">20</span>],[<span class="number">20</span>,<span class="number">30</span>],[<span class="number">42</span>,<span class="number">41</span>]]</span><br><span class="line"><span class="comment"># 之后的坐标</span></span><br><span class="line">position_b = [[<span class="number">14</span>,<span class="number">24</span>],[<span class="number">41</span>,<span class="number">42</span>],[<span class="number">20</span>,<span class="number">31</span>],[<span class="number">42</span>,<span class="number">41</span>]]</span><br><span class="line"><span class="comment"># 使用坐标计算代价矩阵</span></span><br><span class="line">cost_matrix = [[np.power((np.array(a)-np.array(b)),<span class="number">2</span>).<span class="built_in">sum</span>() <span class="keyword">for</span> a <span class="keyword">in</span> position_a] <span class="keyword">for</span> b <span class="keyword">in</span> position_b ]</span><br><span class="line">print(<span class="string">&quot;代价矩阵&quot;</span>)</span><br><span class="line">print(cost_matrix)</span><br><span class="line"><span class="comment"># 进行匈牙利算法匹配</span></span><br><span class="line">row_ind, col_ind = linear_sum_assignment(cost_matrix)</span><br><span class="line">print(<span class="string">&quot;row_index:&quot;</span>, row_ind)</span><br><span class="line">print(<span class="string">&quot;col_index&quot;</span>, col_ind)</span><br><span class="line"><span class="keyword">for</span> x,y <span class="keyword">in</span> <span class="built_in">zip</span>(row_ind, col_ind):</span><br><span class="line">    print(<span class="string">&quot;列表B中的%s,应该与列表A中坐标%s匹配,距离消耗为%d&quot;</span>%(position_b[x],position_a[y],cost_matrix[x][y]))</span><br><span class="line">    </span><br><span class="line"></span><br><span class="line">结果：</span><br><span class="line">代价矩阵</span><br><span class="line">[[<span class="number">32</span>, <span class="number">72</span>, <span class="number">1073</span>], [<span class="number">1445</span>, <span class="number">585</span>, <span class="number">2</span>], [<span class="number">221</span>, <span class="number">1</span>, <span class="number">584</span>], [<span class="number">1465</span>, <span class="number">605</span>, <span class="number">0</span>]]</span><br><span class="line">row_index: [<span class="number">0</span> <span class="number">2</span> <span class="number">3</span>]</span><br><span class="line">col_index [<span class="number">0</span> <span class="number">1</span> <span class="number">2</span>]</span><br><span class="line">列表B中的[<span class="number">14</span>, <span class="number">24</span>],应该与列表A中坐标[<span class="number">10</span>, <span class="number">20</span>]匹配,距离消耗为<span class="number">32</span></span><br><span class="line">列表B中的[<span class="number">20</span>, <span class="number">31</span>],应该与列表A中坐标[<span class="number">20</span>, <span class="number">30</span>]匹配,距离消耗为<span class="number">1</span></span><br><span class="line">列表B中的[<span class="number">42</span>, <span class="number">41</span>],应该与列表A中坐标[<span class="number">42</span>, <span class="number">41</span>]匹配,距离消耗为<span class="number">0</span></span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/02/27/%E9%A2%91%E5%9F%9F%E7%9A%84%E5%91%A8%E6%9C%9F%E5%BB%B6%E6%8B%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/02/27/%E9%A2%91%E5%9F%9F%E7%9A%84%E5%91%A8%E6%9C%9F%E5%BB%B6%E6%8B%93/" class="post-title-link" itemprop="url">频域的周期延拓</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-02-27 20:42:52" itemprop="dateCreated datePublished" datetime="2022-02-27T20:42:52+08:00">2022-02-27</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%9D%82/" itemprop="url" rel="index"><span itemprop="name">杂</span></a>
                </span>
            </span>

          
            <span id="/2022/02/27/%E9%A2%91%E5%9F%9F%E7%9A%84%E5%91%A8%E6%9C%9F%E5%BB%B6%E6%8B%93/" class="post-meta-item leancloud_visitors" data-flag-title="频域的周期延拓" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/02/27/%E9%A2%91%E5%9F%9F%E7%9A%84%E5%91%A8%E6%9C%9F%E5%BB%B6%E6%8B%93/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/02/27/%E9%A2%91%E5%9F%9F%E7%9A%84%E5%91%A8%E6%9C%9F%E5%BB%B6%E6%8B%93/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        关于频域的周期延拓，在知乎上看了一个非常简单明了的文章，原文地址：<a target="_blank" rel="noopener" href="https://www.zhihu.com/question/20236413">https://www.zhihu.com/question/20236413</a> 。</p>
<p>​        <strong><a target="_blank" rel="noopener" href="https://www.zhihu.com/search?q=%E9%A2%91%E5%9F%9F%E5%91%A8%E6%9C%9F%E5%BB%B6%E6%8B%93&search_source=Entity&hybrid_search_source=Entity&hybrid_search_extra=%7B%22sourceType%22:%22answer%22,%22sourceId%22:253229096%7D">频域周期延拓</a>只是表面现象，其实质是不同的信号采样后的像可能相同，不可区分</strong>。这里用简单的三角函数及程序验证，来直观的看一看。</p>
<p>已知 ：</p>
<p>(1) 1Hz的连续余弦信号x1(t)， 对其采样， 采样频率是 Fs = 10 Hz， 得到了1连串的数值x1[n] ;</p>
<p>(2) 11Hz的连续余弦信号x2(t)， 对其采样， 采样频率是Fs = 10 Hz， 得到了1连串的数值x2[n] </p>
<p>画出x1[n]和x2[n]的图像，比较它们的异同。</p>
<figure class="highlight matlab"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">clc; close all;</span><br><span class="line">Fs = <span class="number">10</span>             <span class="comment">% 采样频率 10 Hz</span></span><br><span class="line">Ti = <span class="number">1.0</span>/Fs         <span class="comment">% 采样时间间隔</span></span><br><span class="line">t = <span class="number">0</span>:Ti:<span class="number">2</span>          <span class="comment">% 时间变量 2 秒</span></span><br><span class="line"></span><br><span class="line"><span class="comment">%% 信号 1</span></span><br><span class="line">f1 = <span class="number">1</span>  </span><br><span class="line">x1 = <span class="built_in">cos</span>(<span class="number">2</span>*<span class="built_in">pi</span>*f1*t)</span><br><span class="line"><span class="built_in">figure</span>(<span class="number">1</span>)</span><br><span class="line">subplot(<span class="number">2</span>,<span class="number">1</span>,<span class="number">1</span>)</span><br><span class="line"><span class="built_in">plot</span>(t, x1,<span class="string">&#x27;-o&#x27;</span>) </span><br><span class="line"><span class="built_in">legend</span>(<span class="string">&#x27;x1[n]&#x27;</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment">%% 信号 2 绘图</span></span><br><span class="line">f2 = <span class="number">11</span></span><br><span class="line">x2 = <span class="built_in">cos</span>(<span class="number">2</span>*<span class="built_in">pi</span>*f2*t)</span><br><span class="line"><span class="built_in">figure</span>(<span class="number">1</span>)</span><br><span class="line">subplot(<span class="number">2</span>,<span class="number">1</span>,<span class="number">2</span>)</span><br><span class="line"><span class="built_in">plot</span>(t, x2, <span class="string">&#x27;r-*&#x27;</span>) </span><br><span class="line"><span class="built_in">legend</span>(<span class="string">&#x27;x2[n]&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p>​    你猜这两个信号绘出的时域图有什么区别? 答案是没有区别! 看图:</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/v2-23b295aee0eb9b8b86c2e3aea84e7eba_720w.png" style="zoom:80%;">

<p>​        重要结论: <strong>如果不同的两个连续信号 x1(t)、x2(t)的频率满足一定条件，用频率Fs采样，得到的离散的”像” x1[n]和x2[n]不可区分</strong>。 换句话说:  通过对x1(t)的采样， 我们实际上同时得到了x1(t), x2(t), 甚至 x3(t), …, xn(t) 的采样的像。 它们的“像”是完全等价的, 不可区分。这一组信号 x_n(t) 只需满足:</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20220227205013.png"></p>
<p>​        其中，n 是整数,Fs 是采样频率。也就是说，任何信号的采样，它不仅表示它自己，它还表示一族信号。这一族信号就是该信号的周期延延。在数学上，这一族信号中<strong>不同的信号间的间隔为n*Fs。</strong></p>
<p>​        下面是网友的留言：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220227205238.png" style="zoom:80%;">


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/02/20/python%E5%87%BD%E6%95%B0%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/02/20/python%E5%87%BD%E6%95%B0%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0/" class="post-title-link" itemprop="url">python函数默认参数</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-02-20 11:28:25" itemprop="dateCreated datePublished" datetime="2022-02-20T11:28:25+08:00">2022-02-20</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2022/02/20/python%E5%87%BD%E6%95%B0%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0/" class="post-meta-item leancloud_visitors" data-flag-title="python函数默认参数" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/02/20/python%E5%87%BD%E6%95%B0%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/02/20/python%E5%87%BD%E6%95%B0%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考原文链接: <a target="_blank" rel="noopener" href="https://www.cnblogs.com/crazyrunning/p/6867849.html">https://www.cnblogs.com/crazyrunning/p/6867849.html</a></p>
<h3 id="第一个例子："><a href="#第一个例子：" class="headerlink" title="第一个例子："></a><strong>第一个例子：</strong></h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">bad_append</span>(<span class="params">new_item, a_list=[]</span>):</span></span><br><span class="line">	a_list.append(new_item)</span><br><span class="line">	<span class="keyword">return</span> a_list</span><br><span class="line"></span><br><span class="line">print(bad_append(<span class="string">&#x27;1&#x27;</span>))</span><br><span class="line">print(bad_append(<span class="string">&#x27;2&#x27;</span>))</span><br></pre></td></tr></table></figure>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">结果是：</span><br><span class="line">[<span class="string">&#x27;1&#x27;</span>]</span><br><span class="line">[<span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;2&#x27;</span>]</span><br><span class="line">并不是：</span><br><span class="line">[<span class="string">&#x27;1&#x27;</span>]</span><br><span class="line">[<span class="string">&#x27;2&#x27;</span>]</span><br></pre></td></tr></table></figure>
<p>​    下面通过观察默认参数的内存地址的方式来进行分析：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">bad_append</span>(<span class="params">new_item, a_list=[]</span>):</span></span><br><span class="line">    </span><br><span class="line">    print(<span class="string">&#x27;address of a_list:&#x27;</span>, <span class="built_in">id</span>(a_list))</span><br><span class="line">    a_list.append(new_item)</span><br><span class="line">    <span class="keyword">return</span> a_list</span><br><span class="line"></span><br><span class="line">print(bad_append(<span class="string">&#x27;1&#x27;</span>))</span><br><span class="line">print(bad_append(<span class="string">&#x27;2&#x27;</span>))</span><br><span class="line"></span><br><span class="line">结果显示如下所示：</span><br><span class="line">address of a_list: <span class="number">31128072</span></span><br><span class="line">[<span class="string">&#x27;1&#x27;</span>]</span><br><span class="line">address of a_list: <span class="number">31128072</span></span><br><span class="line">[<span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;2&#x27;</span>]</span><br></pre></td></tr></table></figure>
<p>​        两次调用bad_append，默认参数a_list的地址是相同的。<br>​        <strong>而且a_list是可变对象，使用append方法添加新元素并不会造成list对象的重新创建</strong>，地址的重新分配。这样，‘恰好’就在默认参数指向的地址处修改了对象，下一次调用再次使用这个地址时，就可以看到上一次的修改了。</p>
<p>​        那么，出现上述的输出就不奇怪了，因为它们本来就是指向同一内存地址。</p>
<h3 id="第二个例子："><a href="#第二个例子：" class="headerlink" title="第二个例子："></a><strong>第二个例子：</strong></h3><p>​        当默认参数指向可变类型对象和不可变类型对象时，会表现出不同的行为。<strong>可变默认参数</strong> 的表现就像上面第一个例子一样。<strong>不可变默认参数看下面这个例子</strong>：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">immutable_test</span>(<span class="params">i = <span class="number">1</span></span>):</span></span><br><span class="line">	print(<span class="string">&#x27;before operation, address of i&#x27;</span>, <span class="built_in">id</span>(i))</span><br><span class="line">	i += <span class="number">1</span></span><br><span class="line">	print(<span class="string">&#x27;after operation, address of i&#x27;</span>, <span class="built_in">id</span>(i))</span><br><span class="line">	<span class="keyword">return</span> i</span><br><span class="line">	</span><br><span class="line">print(immutable_test())</span><br><span class="line">print(immutable_test())</span><br><span class="line"></span><br><span class="line">结果：</span><br><span class="line">before operation, address of i <span class="number">1470514832</span></span><br><span class="line">after operation, address of i <span class="number">1470514848</span></span><br><span class="line"><span class="number">2</span></span><br><span class="line">before operation, address of i <span class="number">1470514832</span></span><br><span class="line">after operation, address of i <span class="number">1470514848</span></span><br><span class="line"><span class="number">2</span></span><br></pre></td></tr></table></figure>
<p>​        很明显，第二次调用时默认参数i的值不会受第一次调用的影响。<strong>因为i指向的是不可变对象，对i的操作会造成内存重新分配</strong>，对象重新创建，那么函数中i += 1之后名字i指向了另外的地址；根据默认参数的规则，下次调用时，i指向的地址还是函数定义时赋予的地址，这个地址的值1并没有被改变。</p>
<h3 id="第三个例子："><a href="#第三个例子：" class="headerlink" title="第三个例子："></a>第三个例子：</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">f</span>(<span class="params">a, L=[]</span>):</span></span><br><span class="line">    L.append(a)</span><br><span class="line">    <span class="keyword">return</span> L</span><br><span class="line"> </span><br><span class="line"><span class="built_in">print</span> f(<span class="number">1</span>)</span><br><span class="line"><span class="built_in">print</span> f(<span class="number">2</span>)</span><br><span class="line"><span class="built_in">print</span> f(<span class="number">3</span>)</span><br><span class="line"><span class="built_in">print</span> f(<span class="number">4</span>,[<span class="string">&#x27;x&#x27;</span>])</span><br><span class="line"><span class="built_in">print</span> f(<span class="number">5</span>)</span><br><span class="line"></span><br><span class="line">结果：</span><br><span class="line">[<span class="number">1</span>]</span><br><span class="line">[<span class="number">1</span>, <span class="number">2</span>]</span><br><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]</span><br><span class="line">[<span class="string">&#x27;x&#x27;</span>, <span class="number">4</span>]</span><br><span class="line">[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>]</span><br></pre></td></tr></table></figure>
<p>​        前面的好理解，为什么最后 “print f(5)”的输出是 “[1, 2, 3, 5]”呢？</p>
<p>​        这是因为 “print f(4,[‘x’])”时，默认变量并没有被改变，因为<strong>默认变量</strong>的初始化只是被执行了一次(第一次使用默认值调用)，初始化执行开辟的内存区（我们可以称之为<strong>默认变量</strong>）没有被改变，所以最后的输出结果是“[1, 2, 3, 5]”。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/02/16/numpy%E7%9F%A9%E9%98%B5%E7%9A%84%E9%AB%98%E7%BA%A7%E7%B4%A2%E5%BC%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/02/16/numpy%E7%9F%A9%E9%98%B5%E7%9A%84%E9%AB%98%E7%BA%A7%E7%B4%A2%E5%BC%95/" class="post-title-link" itemprop="url">numpy矩阵的高级索引</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-02-16 10:17:39" itemprop="dateCreated datePublished" datetime="2022-02-16T10:17:39+08:00">2022-02-16</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2022/02/16/numpy%E7%9F%A9%E9%98%B5%E7%9A%84%E9%AB%98%E7%BA%A7%E7%B4%A2%E5%BC%95/" class="post-meta-item leancloud_visitors" data-flag-title="numpy矩阵的高级索引" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/02/16/numpy%E7%9F%A9%E9%98%B5%E7%9A%84%E9%AB%98%E7%BA%A7%E7%B4%A2%E5%BC%95/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/02/16/numpy%E7%9F%A9%E9%98%B5%E7%9A%84%E9%AB%98%E7%BA%A7%E7%B4%A2%E5%BC%95/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考原文链接: <a target="_blank" rel="noopener" href="https://www.cnblogs.com/lzqdeboke/p/14617069.html">https://www.cnblogs.com/lzqdeboke/p/14617069.html</a></p>
<p>​        <strong>直接上例子：</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line">x = np.arange(<span class="number">12</span>).reshape(<span class="number">3</span>,<span class="number">4</span>)</span><br><span class="line">print(x)</span><br><span class="line"></span><br><span class="line">rows = np.array([[<span class="number">0</span>, <span class="number">0</span>], [<span class="number">1</span>, <span class="number">2</span>]])</span><br><span class="line">cols = np.array([[<span class="number">1</span>, <span class="number">2</span>], [<span class="number">2</span>, <span class="number">3</span>]])</span><br><span class="line">print(x[rows, cols])</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220216102646.png" style="zoom:67%;">

<p>​        因为二维数组有两个维度，所以需要两个索引数组rows和cols。索引数组的形状2x2决定了返回数组的形状。</p>
<p>​        各维度的索引值索引原数组的元素，rows的第一个元素0和cols的第一个元素1组成二维数组的索引(0,1)，索引原数组的值1；其余位置依次类推。</p>
<p>​        <strong>再来一个例子：</strong></p>
<p>​        二维矩阵找到每一行的最大值，并且把他们一个个取出来，得到一维矩阵。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line">a = np.array([[<span class="number">1</span>, <span class="number">5</span>, <span class="number">5</span>, <span class="number">2</span>],</span><br><span class="line">              [<span class="number">4</span>, <span class="number">6</span>, <span class="number">2</span>, <span class="number">8</span>],</span><br><span class="line">              [<span class="number">3</span>, <span class="number">7</span>, <span class="number">9</span>, <span class="number">1</span>]])</span><br><span class="line"></span><br><span class="line">max_index = np.argmax(a, axis=<span class="number">1</span>)  <span class="comment"># 每一行的最大值索引</span></span><br><span class="line">print(max_index)</span><br><span class="line">rows = np.arange(<span class="number">3</span>)</span><br><span class="line">cols = max_index</span><br><span class="line">print(a[rows, cols])</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220216104322.png" style="zoom:67%;">


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/01/31/%E5%9C%A8host%E7%AB%AF%E7%BC%96%E8%AF%91%E5%92%8C%E4%BD%BF%E7%94%A8cmsis%20dsp%E5%BA%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/01/31/%E5%9C%A8host%E7%AB%AF%E7%BC%96%E8%AF%91%E5%92%8C%E4%BD%BF%E7%94%A8cmsis%20dsp%E5%BA%93/" class="post-title-link" itemprop="url">在host端编译和使用cmsis dsp库</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-01-31 21:53:03" itemprop="dateCreated datePublished" datetime="2022-01-31T21:53:03+08:00">2022-01-31</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F/" itemprop="url" rel="index"><span itemprop="name">嵌入式</span></a>
                </span>
            </span>

          
            <span id="/2022/01/31/%E5%9C%A8host%E7%AB%AF%E7%BC%96%E8%AF%91%E5%92%8C%E4%BD%BF%E7%94%A8cmsis%20dsp%E5%BA%93/" class="post-meta-item leancloud_visitors" data-flag-title="在host端编译和使用cmsis dsp库" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/01/31/%E5%9C%A8host%E7%AB%AF%E7%BC%96%E8%AF%91%E5%92%8C%E4%BD%BF%E7%94%A8cmsis%20dsp%E5%BA%93/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/01/31/%E5%9C%A8host%E7%AB%AF%E7%BC%96%E8%AF%91%E5%92%8C%E4%BD%BF%E7%94%A8cmsis%20dsp%E5%BA%93/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​         这篇博文的起因是，之前调试算法的时候会用到cmsis的dsp库，那会是在arm平台上实现代码，问题在于调试以及对一致性特别繁琐，原始数据的输入和结果的输出都需要在硬件平台上实现，这实在是令人头大。</p>
<p>​        当时就想是不是可以直接在windows上编译生成库和使用，一开始没找到相关的实现方法，一度还以为这个库只能在arm平台上编译和使用，后来无意中在github上看到了人家讨论的issues(<a target="_blank" rel="noopener" href="https://github.com/ARM-software/CMSIS_5/issues/1015)%EF%BC%8C%E5%8E%9F%E6%9D%A5%E6%98%AF%E6%94%AF%E6%8C%81%E7%9A%84%EF%BC%8C%E9%A1%BF%E6%97%B6%E5%8F%88%E6%9C%89%E4%BA%86%E6%90%9E%E4%B8%8B%E5%8E%BB%E7%9A%84%E4%BF%A1%E5%BF%83%E3%80%82%E6%89%80%E4%BB%A5%E8%87%AA%E5%B7%B1%E5%9C%A8windows%E7%9A%84%E7%8E%AF%E5%A2%83%E4%B8%8B%E8%AF%95%E4%BA%86%E4%B8%80%E6%8A%8A%EF%BC%8C%E5%85%B6%E4%B8%ADwindows%E4%B8%8A%E7%9A%84%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E5%8F%AF%E4%BB%A5%E5%8F%82%E8%80%83%E6%88%91%E4%B9%8B%E5%89%8D%E7%9A%84%E9%82%A3%E7%AF%87%E5%8D%9A%E6%96%87%EF%BC%9Ahttps://xudonglei.gitee.io/2021/08/25/windows%E4%B8%8A%E4%BD%BF%E7%94%A8VSCode%20CMake%E6%9E%84%E5%BB%BAC%20C++%20IDE/">https://github.com/ARM-software/CMSIS_5/issues/1015)，原来是支持的，顿时又有了搞下去的信心。所以自己在windows的环境下试了一把，其中windows上的开发环境可以参考我之前的那篇博文：https://xudonglei.gitee.io/2021/08/25/windows%E4%B8%8A%E4%BD%BF%E7%94%A8VSCode%20CMake%E6%9E%84%E5%BB%BAC%20C++%20IDE/</a> 言归正传，下面就开始在windows上编译和使用cmsis dsp库。</p>
<h3 id="一、获取cmsis-dsp源码"><a href="#一、获取cmsis-dsp源码" class="headerlink" title="一、获取cmsis dsp源码"></a>一、获取cmsis dsp源码</h3><p>​        通过 GitHub 获取也比较方便，地址：<a target="_blank" rel="noopener" href="https://github.com/ARM-software/CMSIS_5">https://github.com/ARM-software/CMSIS_5</a> 。</p>
<h3 id="二、host端编译"><a href="#二、host端编译" class="headerlink" title="二、host端编译"></a>二、host端编译</h3><p>1.将cmsis文件夹中dsp文件夹拷贝出来，我想尽可能的干净，所以就没在整个cmsis文件夹中进行编译。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131144656.png" style="zoom:57%;">

<p>2.在DSP这个根目录，添加CMakeLists.txt文件，内如如下：</p>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">cmake_minimum_required</span> (VERSION <span class="number">3.6</span>)</span><br><span class="line"><span class="keyword">project</span> (testcmsisdsp VERSION <span class="number">0.1</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">set</span>(ROOT E:/Ready_For/CMSISDSP_HOST)</span><br><span class="line"><span class="keyword">set</span>(DSP <span class="variable">$&#123;ROOT&#125;</span>/DSP)</span><br><span class="line"><span class="keyword">SET</span>(CMAKE_C_FLAGS_DEBUG <span class="string">&quot;-DHOST=ON -D_DEBUG -D__GNUC_PYTHON__&quot;</span> CACHE INTERNAL <span class="string">&quot;&quot;</span>) </span><br><span class="line"></span><br><span class="line"><span class="comment">#head file path</span></span><br><span class="line"><span class="keyword">INCLUDE_DIRECTORIES</span>(<span class="string">&quot;$&#123;DSP&#125;/Include&quot;</span>)</span><br><span class="line"><span class="keyword">INCLUDE_DIRECTORIES</span>(<span class="string">&quot;$&#123;DSP&#125;/PrivateInclude&quot;</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">list</span>(APPEND CMAKE_MODULE_PATH <span class="variable">$&#123;DSP&#125;</span>)</span><br><span class="line"><span class="keyword">add_subdirectory</span>(<span class="string">&quot;$&#123;DSP&#125;/Source&quot;</span> bin_dsp)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span>(compilerSpecificCompileOptions PROJECTNAME <span class="string">&quot;$&#123;ROOT&#125;&quot;</span>)</span><br><span class="line"><span class="keyword">endfunction</span>()</span><br></pre></td></tr></table></figure>
<p>3.然后进行配置，会报下面的错误：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131152708.png" style="zoom:50%;">

<p>应该是路径包含的问题，我为了方便起见，直接把三个cmake文件从DSP/Source目录下拷贝到DSP目录下。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131153040.png" style="zoom:67%;">

<p>再进行编译，这时候就报最后一个错误了：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131153418.png" style="zoom:67%;">

<p>这个错误是因为写的那个CMakeLists.txt中定义的空函数位置放的不对，需要放在下面这个地方：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131160420.png" style="zoom:67%;">

<p>之所以想到要加那个空函数，可以看下面这个简单解释：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131160452.png" style="zoom:80%;">

<p>然后再单个编译生成静态库就可以了：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131162715.png" style="zoom:67%;">

<h3 id="三、使用"><a href="#三、使用" class="headerlink" title="三、使用"></a>三、使用</h3><p>​        下面跑一个fft计算的例子，看如何使用生成的静态库。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/微信截图_20220131202419.png" style="zoom:80%;">

<p>这样跑下来确认可行的，使用的时候可以根据实际的文件路径修改上面这个CMakeLists.txt。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/01/22/roll%E3%80%81pitch%E3%80%81yaw/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/01/22/roll%E3%80%81pitch%E3%80%81yaw/" class="post-title-link" itemprop="url">roll、pitch、yaw</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-01-22 18:46:04" itemprop="dateCreated datePublished" datetime="2022-01-22T18:46:04+08:00">2022-01-22</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2022/01/22/roll%E3%80%81pitch%E3%80%81yaw/" class="post-meta-item leancloud_visitors" data-flag-title="roll、pitch、yaw" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/01/22/roll%E3%80%81pitch%E3%80%81yaw/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/01/22/roll%E3%80%81pitch%E3%80%81yaw/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        参考原文链接：<a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_37362454/article/details/103722229">https://blog.csdn.net/m0_37362454/article/details/103722229</a></p>
<p>​                                  <a target="_blank" rel="noopener" href="https://www.guyuehome.com/35087">https://www.guyuehome.com/35087</a></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202201221853931.png" style="zoom:63%;">

<p><strong>a. pitch</strong></p>
<p>​        俯仰角描述载体“抬头”的角度大小，一般以抬头(向上)为正，低头(向下)为负</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202201221856029.gif"></p>
<p><strong>b.roll</strong></p>
<p>​        描述载体“侧身”的角度大小，一般以绕着正前方逆时针旋转为正，顺时针旋转为负。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202201221859683.webp"></p>
<p><strong>c. yaw</strong></p>
<p>​        航向描述载体的朝向，一般以逆时针旋转为正，顺时针旋转为负。</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202201221903393.webp"></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/01/19/Windows10%E5%AE%89%E8%A3%85TensorFlow(GPU%E7%89%88)+Keras/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/01/19/Windows10%E5%AE%89%E8%A3%85TensorFlow(GPU%E7%89%88)+Keras/" class="post-title-link" itemprop="url">Windows10安装TensorFlow(GPU版)+Keras</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-01-19 21:24:07" itemprop="dateCreated datePublished" datetime="2022-01-19T21:24:07+08:00">2022-01-19</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2022/01/19/Windows10%E5%AE%89%E8%A3%85TensorFlow(GPU%E7%89%88)+Keras/" class="post-meta-item leancloud_visitors" data-flag-title="Windows10安装TensorFlow(GPU版)+Keras" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/01/19/Windows10%E5%AE%89%E8%A3%85TensorFlow(GPU%E7%89%88)+Keras/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/01/19/Windows10%E5%AE%89%E8%A3%85TensorFlow(GPU%E7%89%88)+Keras/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>1.Windows查看显卡(GTX1650)支持的CUDA版本号，支持的CUDA版本号—&gt; 11.0.218</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imag1313e.png" style="zoom:67%;">

<p>​        但是看了tensorflow_gpu不同版本支持的cuda版本如下：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Idddmage.png" style="zoom:80%;">

<p>​        可以看出tensorflow2.3.0要配上python3.8并且适配cuda11.0，但我们还是想用tensorflow1.14.0这个版本，所以猜想GTX1650应该是向下兼容cuda版本号的。</p>
<p>​        另外看了网友使用的版本以及<a target="_blank" rel="noopener" href="https://github.com/fo40225/tensorflow-windows-wheel">https://github.com/fo40225/tensorflow-windows-wheel</a> 中的说明可以知道需要下载使用的cuda版本号。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Ima888ge.png" style="zoom:80%;">

<p>​        在<a target="_blank" rel="noopener" href="https://developer.nvidia.com/cuda-toolkit-archive">https://developer.nvidia.com/cuda-toolkit-archive</a> 下载cuda版本10.1的</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imag34355e.png" style="zoom:80%;">

<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image22111.png"></p>
<p>​        说明安装成功。</p>
<p>​        再安装cuDNN，其实这只是一个基于cuda的库，不需要安装，下载后的压缩包解压后是一些头文件，lib和dll（windows操作系统）文件。cudnn下载地址：（需要登录）<a target="_blank" rel="noopener" href="https://developer.nvidia.com/rdp/cudnn-download">https://developer.nvidia.com/rdp/cudnn-download</a> ，选择和cuda10.1对应的版本。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagwwwwe.png" style="zoom:80%;">

<p>​        解压后把cuDNN中bin，include，lib文件夹下的文件对应的复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1中相对应文件夹即可。</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image555555342.png" style="zoom:80%;">



<p>2.接下来开始用ANACONDA安装TENSORFLOW  </p>
<p>​        2.1 在ANACONDA里创建名为TENSORFLOW的环境（你可以叫他任何名字，这里我叫这个环境为TENSORFLOW。）      </p>
<p>​         conda create -n tensorflow pip python=3.7       </p>
<p>​        这里pip python=3.7的意思是在名为tensorflow的环境里搭建版本是3.7的python。<br>​        2.2 发出以下命令以激活 conda 环境：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagecvcv.png" style="zoom:80%;">

<p>​        2.3 conda 环境中安装 TensorFlow。先在<a target="_blank" rel="noopener" href="https://github.com/fo40225/tensorflow-windows-wheel/blob/master/1.14.0/py37/GPU/cuda101cudnn76sse2/tensorflow_gpu-1.14.0-cp37-cp37m-win_amd64.whl">https://github.com/fo40225/tensorflow-windows-wheel/blob/master/1.14.0/py37/GPU/cuda101cudnn76sse2/tensorflow_gpu-1.14.0-cp37-cp37m-win_amd64.whl</a> 中把要安装的文件下载下来，然后输入以下命令：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagehhhh.png" style="zoom:80%;">

<p>​        2.4 测试是否安装成功  </p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagezzzz.png"></p>
<p>​        关于这个问题numpy降级就可以了：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image89098.png" style="zoom:80%;">

<p>​        如果想检测tensorflow的确用gpu来做运算，请用以下脚本做测试：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> tensorflow <span class="keyword">as</span> tf</span><br><span class="line"><span class="comment"># Creates a graph.</span></span><br><span class="line">a = tf.constant([<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>, <span class="number">4.0</span>, <span class="number">5.0</span>, <span class="number">6.0</span>], shape=[<span class="number">2</span>, <span class="number">3</span>], name=<span class="string">&#x27;a&#x27;</span>)</span><br><span class="line">b = tf.constant([<span class="number">1.0</span>, <span class="number">2.0</span>, <span class="number">3.0</span>, <span class="number">4.0</span>, <span class="number">5.0</span>, <span class="number">6.0</span>], shape=[<span class="number">3</span>, <span class="number">2</span>], name=<span class="string">&#x27;b&#x27;</span>)</span><br><span class="line">c = tf.matmul(a, b)</span><br><span class="line"><span class="comment"># Creates a session with log_device_placement set to True.</span></span><br><span class="line">sess = tf.Session(config=tf.ConfigProto(log_device_placement=<span class="literal">True</span>))</span><br><span class="line"><span class="comment"># Runs the op.</span></span><br><span class="line">print(sess.run(c))</span><br></pre></td></tr></table></figure>
<p>​        测试结果如下：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagecccc.png"></p>
<p> 图中device:GPU:0的意思就是说该运算用到了GPU。</p>
<p>3.Keras安装   </p>
<p>​        安装Keras之前要查看自己安装的TensorFlow的版本对应的Keras版本，参考一下图片：</p>
<p><img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagezzz.png"></p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagexxx.png" style="zoom:80%;">

<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imageaaaa.png" style="zoom:80%;">



<p><strong>补充知识：关于conda的一些基本操作</strong></p>
<p>1.从某个环境中退出来：</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Image999oo.png" style="zoom:80%;">

<p>2.删除自己的某个虚拟环境</p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/Imagddd.png" style="zoom:80%;">

<p>3.当你需要删除tensorflow package的时候，如果安装的时候是用pip安装的，那么删除的时候也要用pip。 同理，用conda安装的要用conda指令来删除。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2022/01/09/opengl%E4%B8%ADglRotatef/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="xudonglei">
      <meta itemprop="description" content="搬砖 嵌入式">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="学无止境">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2022/01/09/opengl%E4%B8%ADglRotatef/" class="post-title-link" itemprop="url">opengl中glRotatef</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2022-01-09 15:03:37" itemprop="dateCreated datePublished" datetime="2022-01-09T15:03:37+08:00">2022-01-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a>
                </span>
            </span>

          
            <span id="/2022/01/09/opengl%E4%B8%ADglRotatef/" class="post-meta-item leancloud_visitors" data-flag-title="opengl中glRotatef" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2022/01/09/opengl%E4%B8%ADglRotatef/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2022/01/09/opengl%E4%B8%ADglRotatef/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>​        部分参考文章原文地址：<a target="_blank" rel="noopener" href="https://segmentfault.com/a/1190000002695992">https://segmentfault.com/a/1190000002695992</a></p>
<p>​                                                <a target="_blank" rel="noopener" href="https://doc.yonyoucloud.com/doc/wiki/project/opengl-es-basics/coordinate-transformation.html">https://doc.yonyoucloud.com/doc/wiki/project/opengl-es-basics/coordinate-transformation.html</a></p>
<p>​        glRotatef(GLfloat angle,GLfloat x,GLfloat y,GLfloat z)<br>​        glRotatef(45,1,0,0)<br>​        物体如何旋转？想象：从 坐标（0，0，0）即原点，引出一条线到（1,0,0）,用右手握住这条线，这时，你会问，如何握？右手大拇指指向 （0，0，0）至（1，0，0）的方向 才握。另外四个手指的弯曲指向 即是物体旋转方向。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> pygame</span><br><span class="line"><span class="keyword">from</span> pygame.<span class="built_in">locals</span> <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> OpenGL.GL <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> OpenGL.GLU <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line">verticies = (</span><br><span class="line">    (<span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>),</span><br><span class="line">    (<span class="number">1</span>, <span class="number">1</span>, -<span class="number">1</span>),</span><br><span class="line">    (-<span class="number">1</span>, <span class="number">1</span>, -<span class="number">1</span>),</span><br><span class="line">    (-<span class="number">1</span>, -<span class="number">1</span>, -<span class="number">1</span>),</span><br><span class="line">    (<span class="number">1</span>, -<span class="number">1</span>, <span class="number">1</span>),</span><br><span class="line">    (<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>),</span><br><span class="line">    (-<span class="number">1</span>, -<span class="number">1</span>, <span class="number">1</span>),</span><br><span class="line">    (-<span class="number">1</span>, <span class="number">1</span>, <span class="number">1</span>)</span><br><span class="line">    )</span><br><span class="line">edges = (</span><br><span class="line">    (<span class="number">0</span>,<span class="number">1</span>),</span><br><span class="line">    (<span class="number">0</span>,<span class="number">3</span>),</span><br><span class="line">    (<span class="number">0</span>,<span class="number">4</span>),</span><br><span class="line">    (<span class="number">2</span>,<span class="number">1</span>),</span><br><span class="line">    (<span class="number">2</span>,<span class="number">3</span>),</span><br><span class="line">    (<span class="number">2</span>,<span class="number">7</span>),</span><br><span class="line">    (<span class="number">6</span>,<span class="number">3</span>),</span><br><span class="line">    (<span class="number">6</span>,<span class="number">4</span>),</span><br><span class="line">    (<span class="number">6</span>,<span class="number">7</span>),</span><br><span class="line">    (<span class="number">5</span>,<span class="number">1</span>),</span><br><span class="line">    (<span class="number">5</span>,<span class="number">4</span>),</span><br><span class="line">    (<span class="number">5</span>,<span class="number">7</span>)</span><br><span class="line">    )</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Cube</span>():</span></span><br><span class="line">    glBegin(GL_LINES)</span><br><span class="line">    <span class="keyword">for</span> edge <span class="keyword">in</span> edges:</span><br><span class="line">        <span class="keyword">for</span> vertex <span class="keyword">in</span> edge:</span><br><span class="line">            glVertex3fv(verticies[vertex])</span><br><span class="line">    glEnd()</span><br><span class="line">    </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">    pygame.init()</span><br><span class="line">    display = (<span class="number">640</span>, <span class="number">480</span>)</span><br><span class="line">    pygame.display.set_mode(display, DOUBLEBUF | OPENGL)</span><br><span class="line"></span><br><span class="line">    gluPerspective(<span class="number">45</span>, (display[<span class="number">0</span>]/display[<span class="number">1</span>]), <span class="number">0.1</span>, <span class="number">50.0</span>)</span><br><span class="line">    glTranslatef(<span class="number">0</span>, <span class="number">0</span>, -<span class="number">5</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">        glRotatef(<span class="number">10</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>)</span><br><span class="line">        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)</span><br><span class="line"></span><br><span class="line">        Cube()</span><br><span class="line">        pygame.display.flip()</span><br><span class="line">        pygame.time.wait(<span class="number">300</span>)</span><br><span class="line">main()</span><br></pre></td></tr></table></figure>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202201091522251.gif" style="zoom:57%;">

<p><strong>补充：网上的其他一些例子</strong></p>
<p>​        比如你选择一个骰子，首先按下列顺序旋转3次：</p>
<p>​        gl.glRotatef(90f, 1.0f, 0.0f, 0.0f); </p>
<p>​        gl.glRotatef(90f, 0.0f, 1.0f, 0.0f); </p>
<p>​        gl.glRotatef(90f, 0.0f, 0.0f, 1.0f); </p>
<img src="https://xdl-blog-picture.oss-cn-shanghai.aliyuncs.com/img/202201091532519.png" style="zoom:70%;">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/17/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/17/">17</a><span class="page-number current">18</span><a class="page-number" href="/page/19/">19</a><span class="space">&hellip;</span><a class="page-number" href="/page/29/">29</a><a class="extend next" rel="next" href="/page/19/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">xudonglei</p>
  <div class="site-description" itemprop="description">搬砖 嵌入式</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">283</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">67</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2024</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xudonglei</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'BT0Qw9HcTpPv1a6cT1iDBXKz-gzGzoHsz',
      appKey     : 'LMCMh8v02JTMFAwKNRcgoizI',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
